APPLY TO SELECTION ({file}; statement) Pg 40-7 file File File for which to apply statement statement Statement One line of code or a global procedure APPLY TO SELECTION applies statement to each record in the current selection of file. The statement can be a statement or a global procedure. If statement modifies a record of file, the modified record is saved. If statement does not modify a record, the record is not saved. If the current selection is empty, APPLY TO SELECTION has no effect. The statement can contain a field from a related file if the relation is automatic. APPLY TO SELECTION can be used to gather information from the selection of records (for example, a total), or to modify a selection (for example, changing the first letter of a field to uppercase). If this command is used within a transaction, all changes made can be undone if the transaction is cancelled. 4D SERVER: The server does not execute any of the commands that may be passed in statement. Every record in the selection will be sent back to the local workstation to be modified. The progress thermometer is displayed while APPLY TO SELECTION is executing. The MESSAGES OFF command turns off the progress indicator for the process in which it is executed. If the progress indicator is displayed, the user can cancel the operation. If the user cancels, the OK system variable is set to 0. Otherwise, the OK system variable is set to 1. The following example capitalizes all the names in the file. It uses character reference symbols (the ≤ and ≥ characters) to access the first character of the field: APPLY TO SELECTlON([People]; [People]Name≤1≥:=Uppercase ([People]Name≤1≥)) If a record is locked during the execution of APPLY TO SELECTION and that record is modified, the record will not be saved. Any locked records are put in a set called LockedSet. After APPLY TO SELECTION has executed, test the LockedSet to see if any records were locked. The following loop will execute until all the records have been modified: Repeat ` Repeat if for any locked records APPLY TO SELECTlON([People]; [People]Name≤1≥:=Uppercase ([People]Name≤1≥)) USE SET ("LockedSet") ` Select only locked records Until (Records in set ("LockedSet") = 0) ` Done when there are no locked records See also: USE SET